package com.map.core.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库连接
 * @author Daisn
 *
 */
public class JDBCUtils {

	private static JDBCUtils instance = new JDBCUtils();

	private JDBCUtils() {

	}

	public static JDBCUtils getInstance() {
		return instance;
	}

	public Connection getJDBCConnection() {
		String URL = "jdbc:mysql://172.18.100.40:13361/test?characterEncoding=utf8";
		String USER = "root";
		String PASSWORD = "123456";
		Connection conn = null;
		try {
			// 1.加载驱动程序
			Class.forName("com.mysql.jdbc.Driver");
			// 2.获得数据库链接
			conn = DriverManager.getConnection(URL, USER, PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	  public static void close(Connection conn){  
	        if(conn != null){  
	            try {  
	                conn.close();  
	            } catch (SQLException e) {  
	                e.printStackTrace();  
	            }  
	        }  
	    } 
}
